package com.test;

import java.util.Scanner;
import java.util.Stack;

public class test {
    public static void main(String[] args) {
        Stack<Character> stack = new Stack();
        Scanner in = new Scanner(System.in);
        System.out.print("输入字符串:");
        String a = in.next();
        char[] arr = a.toCharArray();
        char arr1;
        int i = 0;
        while (true) {
            if (arr[i] != ')' && arr[i] != ']') {
                stack.push(arr[i]);
                i++;
            } else {
                if (stack.isEmpty() && i == arr.length - 1) {
                    System.out.println("括号匹配");
                    return;
                }
                arr1 = stack.pop();
//                if (arr1 != arr[i]) {
//                    System.out.println("括号不匹配");
//                    return;
//                }
                switch (arr1) {
                    case '(':
                        if (arr[i] != ')') {
                            System.out.println("括号不匹配");
                            return;
                        }
                        break;
                    case '[':
                        if (arr[i] != ']') {
                            System.out.println("括号不匹配");
                            return;
                        }
                        break;
                }
            }
        }


    }
}
